package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ShoppingCartMapper {

    /**
     * 将数据插入购物车中
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart (name, image, user_id, dish_id, setmeal_id, dish_flavor, amount, create_time) " +
            "VALUES (#{name},#{image},#{userId},#{dishId},#{setmealId},#{dishFlavor},#{amount},#{createTime})")
    void insertShoppingCart(ShoppingCart shoppingCart);

    /**
     * 根据条件查询购物车中的数据
     * @param shoppingCart
     * @return
     */
    List<ShoppingCart> select(ShoppingCart shoppingCart);

    /**
     * 修改购物车中的菜品或套餐
     * @param shoppingCartOne
     */
    void upDateShoppingCart(ShoppingCart shoppingCartOne);

    /**
     * 根据用户id，获取购物车的所有信息
     * @param userId
     * @return
     */
    @Select("select id, name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> attainShoppingCart(Long userId);

    /**
     * 根据用户id删除购物车商品
     * @param userId
     */
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    /**
     * 根据id删除购物车商品
     * @param id
     */
    @Delete("delete from shopping_cart where id =#{id}")
    void deleteById(Long id);
}
